package lovoStudy_9_13.Puck;

import java.util.*;

/**
 * Created with Intellij IDEA
 * Description:
 *
 * @ return:
 * @ author:zxl
 */
//public class DouDiZhu {
//    //List subList
//    private ArrayList<Puck> arrayList = new ArrayList<>();
//
//    public void process(){
//        init();
//        shuffle();
//        sendCard();
//    }
//
//    /**
//     * 初始化54张扑克牌
//     */
//    public void init(){
//// 3 4 5 6 7 8 9 10 j Q K A 2 x X
//        wo(arrayList,"♦");
//        wo(arrayList,"♣");
//        wo(arrayList,"♥");
//        wo(arrayList,"♠");
//        arrayList.add(new Puck("小王","JOKER",16));
//        arrayList.add(new Puck("大王","JOKER",17));
//    }
//
//    /**
//     * 产生扑克对象方法
//     * */
//    public void wo(ArrayList arrayList,String type){
//        for (int i = 2 ; i <= 14 ; i++){
//            if (i == 2){
//                arrayList.add(new Puck( i  + "",type,15));
//                continue;
//            }
//            if (i == 11){
//                arrayList.add(new Puck( "j",type,11));
//                continue;
//            }
//            if (i == 12){
//                arrayList.add(new Puck( "Q",type,12));
//                continue;
//            }
//            if (i == 13){
//                arrayList.add(new Puck( "K",type,13));
//                continue;
//            }
//            if (i == 14){
//                arrayList.add(new Puck( "A",type,14));
//                continue;
//            }
//            arrayList.add(new Puck( i  + "",type,i));
//        }
//    }
//    /**
//     * 洗牌
//     */
//    public void shuffle(){
//        Collections.shuffle(arrayList);
//    }
//
//    /**
//     * 发牌
//     */
//    public void sendCard(){
//        List<Puck> player1 = wow(0,17);
//        List<Puck> player2 = wow(17,34);
//        List<Puck> player3 = wow(34,51);
//        List<Puck> diZhu= wow(51,54);
//
//                for (Puck puck : player1 ){
//            System.out.print(puck.getPoint() + "" + puck.getType() + " ");
//        }
//        System.out.println();
//        for (Puck puck : player2 ){
//            System.out.print(puck.getPoint() + "" + puck.getType() + " ");
//        }
//        System.out.println();
//        for (Puck puck : player3 ){
//            System.out.print(puck.getPoint() + "" + puck.getType() +  " ");
//        }
//    }
//
//    public List<Puck> wow(int a, int b){
//        List<Puck> newArrayList =  arrayList.subList(a,b);
//        Collections.sort(newArrayList, new Comparator<Puck>() {
//            @Override
//            public int compare(Puck o1, Puck o2) {
//
//
//
//                return o2.getNum() - o1.getNum();
//            }
//        });
//        return newArrayList;
//
//    }
//
//
//
//
//}
public class DouDiZhu {
    private static ArrayList<Puke> pukes = new ArrayList<>();

    /**
     * 初始化54张扑克牌
     */
    public void init(){
        String [] points = "3,4,5,6,7,8,9,10,J,Q,K,A,2".split(",");
        String [] types = "♠,♥,♣,♦".split(",");
        for(int i = 0;i < points.length;i++){
            for (int j = 0;j < types.length;j++){

                pukes.add(new Puke(points[i],types[j],i,j,"images\\" + (i+3) +"_" + (j+1)));
            }
        }
        pukes.add(new Puke("大王","",14,0,"images\\" + 17 +"_" + 1));
        pukes.add(new Puke("小王","",13,0,"images\\" + 16 +"_" + 1));

    }

    /**
     * 洗牌
     */
    public void shuffle(){
        Collections.shuffle(pukes);
        System.out.println(pukes);
    }

    /**
     * 发牌
     */
    public void sendCard(){
        List playerOne = pukes.subList(0,17);
        List playerTwo = pukes.subList(17,34);
        List playerThree = pukes.subList(34,51);
        List base = pukes.subList(51,54);

        sort(playerOne);

        sort(playerTwo);
        sort(playerThree);


//        String one = playerOne.toString();
//        String two = one.substring(1,one.length()-1);
//        System.out.println(two);
//        String [] pathName = two.split(",");
//        for (int i = 0; i< pathName.length;i++){
//            System.out.println(pathName[i]);
//        }


//        System.out.println(one.length);
//        for (int i = 0; i< one.length; i++){
//            System.out.println(one[i]);
//        }

        System.out.println();
        String[] b= getArray(base);
        for (int i = 0; i< b.length; i++){
            System.out.println(b[i]);
        }


        new PuckJFrame(getArray(playerOne),getArray(playerTwo),getArray(playerThree),getArray(base));
        System.out.println("玩家一：" + playerOne);
        System.out.println("玩家二：" + playerTwo);
        System.out.println("玩家三：" + playerThree);
        System.out.println("玩家四：" + base);
    }
    private String [] getArray(List list){
        String one = list.toString();
        String two = one.substring(1,one.length()-1);
        String [] pathName = two.split(",");
        return pathName;
    }



    private void sort(List list){
        Collections.sort(list, new Comparator<Puke>() {
            @Override
            public int compare(Puke o1, Puke o2) {
                if (o1.getPointValue()== o2.getPointValue()){
                    return o1.getTypeValue() - o2.getTypeValue();
                }else {
                    return o2.getPointValue() - o1.getPointValue();
                }
            }
        });
    }




    public static void main(String[] args) {

        DouDiZhu douDiZhu = new DouDiZhu();
        douDiZhu.init();
        douDiZhu.shuffle();
        douDiZhu.sendCard();
    }
}